package com.qianhui.bean;

import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.StringEntity;
import weixin.popular.api.BaseAPI;
import weixin.popular.bean.BaseResult;
import weixin.popular.client.LocalHttpClient;

import java.nio.charset.Charset;

public class CustomServiceAPI extends BaseAPI
{
    /**
     * 创建客服会话
     *
     * @param access_token
     * @param messageJson
     * @return
     */
    public static BaseResult customServiceCreate(String access_token, String kf_account, String openid, String text)
    {
        String postJsonData = String.format("{\"kf_account\":\"%1$s\" ,\"openid\": \"%2$s\",\"text\": \"%3$s\"}", kf_account, openid, text);
        HttpUriRequest httpUriRequest = RequestBuilder.post().setHeader(jsonHeader).setUri(BASE_URI + "/customservice/kfsession/create").addParameter("access_token", access_token).setEntity(new StringEntity(postJsonData, Charset.forName("utf-8"))).build();
        return LocalHttpClient.executeJsonResult(httpUriRequest, BaseResult.class);
    }

}
